<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>查询页面</title>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <link rel="stylesheet" href="../../../css/api.css">
    <style media="screen">
        * {
            padding: 0;
            margin: 0;
        }

        input {
            border: 0; // 去除未选中状态边框
            outline: none!important; // 去除选中状态边框
            background-color: rgba(0, 0, 0, 0); // 透明背景
            text-align: center;
        }

        header {
            height: 0rem;
            background-color: #333;
        }

        body {
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-flex-flow: column;
        }

        .contanier {
            height: 80%;
        }

        .inputMessage {
            height: 50%;
            width: 80%;
            margin: 30% auto 10%;
        }

        #phone_number {
            outline: none;
            width: 100%;
            height: auto;
            padding: 2% 0;
            border: 1px solid #ccc;
            font-size: 1.5rem;
            border-radius: 5px;
            text-align: center;
        }

        #query-message {
            height: 15%;
            width: 80%;
            margin: auto;
            background: #3fd5a5;
            font-size: 1.5rem;
            color: #fff;
            text-align: center;
            display: flex;
            justify-content: center;
            align-items: center;
            border-radius: 15px;
        }

        .touch-down {
            opacity: .4;
        }
    </style>
</head>

<body>
    <header>

    </header>
    <section class="contanier">
        <section class="inputMessage">
            <input type="number" placeholder="请输入电话号码" id="phone_number" />
        </section>
        <section id="query-message" tapmode="touch-down">查询</section>
    </section>
    <footer></footer>
</body>
<script type="text/javascript" src="../../../script/api.js"></script>
<script type="text/javascript" src="../../../script/request.js"></script>
<script type="text/javascript">
    function initFront() {
        api.parseTapmode()
        var queryMessage = $api.byId('query-message')
        $api.addEvt(queryMessage, 'touchend', function() {
            var phone = $api.byId('phone_number')
            phone = $api.val(phone)
            var request = new Request('farmer_search');
            request.searchFarmer(phone, function(response, error) {
              console.log(response);
                response = JSON.parse(response)
                console.log(response);
                 var farmers = response.farmers
                console.log(farmers);
                for (var i = 0; i < farmers.length; i++) {
                }
                if (response.code == '0') {
                    if (farmers.length == 1) {
                        var id = response.farmers[0].id;
                        api.openWin({
                            name: 'farmer_win',
                            url: '../../../html/farmer_win.html',
                            pageParam: {
                                id: id
                            }
                        });
                    }
                    if (farmers.length > 1) {
                        api.openFrame({
                            name: 'dialog_frame',
                            url: '../../../html/dialog_frame.html',
                            type: "none",
                            rect: {
                                x: 0,
                                y: 0,
                                w: 'auto',
                                h: 'auto'
                            },
                            bgColor: 'rgba(0,0,0,0.6)',
                            bounces: false,
                            pageParam: {
                                response: response
                            },
                        });
                    }
                } else {
                    if (farmers.length == 0 && response.code == '404') {
                        api.openWin({
                            name: 'nodata_win',
                            url: '../../../html/nodata_win.html',
                            pageParam: {
                                name: 'test'
                            }
                        });
                    } else {

                    }
                }
            });
        });

    }

    apiready = function() {
        initFront();
    }
</script>

</html>
